package com.ff.utils;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
import com.aliyuncs.dysmsapi.model.v20170525.*;

public class SendPhone {
//    //产品名称:云通信短信API产品,开发者无需替换
//    private static final String product = "Dysmsapi";
//    //产品域名,开发者无需替换
//    private static final String domain = "dysmsapi.aliyuncs.com";
    private final static String accessKeyId="LTAI5tGVDeyyGc4REq45tg5S";
    private final static String AccessKeySecret="C1pXs4VZpW2FUfec0YzbL822eV6Mcs";
    public static void sendPhone(String phone,String code) throws ClientException {

        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, AccessKeySecret);
        /** use STS Token
         DefaultProfile profile = DefaultProfile.getProfile(
         "<your-region-id>",           // The region ID
         "<your-access-key-id>",       // The AccessKey ID of the RAM account
         "<your-access-key-secret>",   // The AccessKey Secret of the RAM account
         "<your-sts-token>");          // STS Token
         **/
//        DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
        IAcsClient client = new DefaultAcsClient(profile);

//        int code = ValidateCodeUtils.generateValidateCode(6);

        SendSmsRequest request = new SendSmsRequest();
        request.setPhoneNumbers(phone);
        request.setSignName("pet宠物项目系统");
        request.setTemplateCode("SMS_270290677");
        request.setTemplateParam("{\"code\":\""+code+"\"}");
        request.setOutId("123");

        try {
            SendSmsResponse response = client.getAcsResponse(request);
            System.out.println("手机号为"+phone+"正在登录"+"  验证码为"+code);
            System.out.println(new Gson().toJson(response));
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            System.out.println("ErrCode:" + e.getErrCode());
            System.out.println("ErrMsg:" + e.getErrMsg());
            System.out.println("RequestId:" + e.getRequestId());
        }

    }
}